//
//  WBHomeToolBar.swift
//  weibo
//
//  Created by 胡古古 on 2017/6/8.
//  Copyright © 2017年 hugugu. All rights reserved.
//

import UIKit

class WBHomeToolBar: UIView {
    
    var statusViewModel: WBStatusViewModel? {
        
        didSet {
            
            
                retweetButton.setTitle(statusViewModel?.reposts, for: .normal)
            
                commnetButton.setTitle(statusViewModel?.comments, for: .normal)
            
                unlikeButton.setTitle(statusViewModel?.attitudes, for: .normal)
            
        
        }
        
    }
    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        setupUI()
    }
    
    var retweetButton: UIButton!
    var commnetButton: UIButton!
    var unlikeButton: UIButton!
    
    
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        
        let retweetButton = createButton(title: "  转发", imageName: "timeline_icon_retweet")
        self.retweetButton = retweetButton
        let commnetButton = createButton(title: "  评论", imageName: "timeline_icon_comment")
        self.commnetButton = commnetButton
        let unlikeButton = createButton(title: "  赞", imageName:"timeline_icon_unlike")
        self.unlikeButton = unlikeButton
        let oneLine = createLineView()
        let twoLine = createLineView()
        
        addSubview(retweetButton)
        addSubview(commnetButton)
        addSubview(unlikeButton)
        addSubview(oneLine)
        addSubview(twoLine)

        retweetButton.snp.makeConstraints { (make) in
            
            make.top.left.bottom.equalTo(self)
        }
        
        commnetButton.snp.makeConstraints { (make) in
            
            make.top.bottom.equalTo(retweetButton)
            make.left.equalTo(retweetButton.snp.right)
            make.width.equalTo(retweetButton)
        }
        
        unlikeButton.snp.makeConstraints { (make) in
            
            make.top.bottom.equalTo(commnetButton)
            make.left.equalTo(commnetButton.snp.right)
            make.width.equalTo(retweetButton)
            make.right.equalTo(self)
        }
        
        oneLine.snp.makeConstraints { (make) in
            
            make.centerX.equalTo(retweetButton.snp.right)
            make.centerY.equalTo(self)
        }
        
        twoLine.snp.makeConstraints { (make) in
            
            make.centerX.equalTo(commnetButton.snp.right)
            make.centerY.equalTo(self)
        }
        
    }

    private func createButton(title:String,imageName:String) ->UIButton {
        
        let button = UIButton()
        button.setTitle(title, for: .normal)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.adjustsImageWhenHighlighted = false
        button.setImage(UIImage(named:imageName), for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.setBackgroundImage(UIImage(named:"timeline_card_bottom_background"), for: .normal)
        
        return button
    }
    
    private func createLineView() ->UIImageView {
        
        let imageView = UIImageView(image: UIImage(named:"timeline_card_bottom_line"))
        return imageView
    }
}
